/**
 * @param {number[]} students
 * @param {number[]} sandwiches
 * @return {number}
 */
var countStudents = function(students, sandwiches) {
  let stuArr = [];
  for(let i = 0; i < students.length; i++) {
    let obj = {
      value: students[i],
      dislike: false
    };
    stuArr.push(obj);
  }
  function allDislike(arr) {
    for(let i = 0; i < arr.length; i++) {
      if(!arr[i].dislike) return false;
    }
    return true;
  }

  function clearAllDislike() {
    for(let i = 0; i < stuArr.length; i++) {
      stuArr[i].dislike = false;
    }
  }

  while(sandwiches.length) {
    if(stuArr[0].value == sandwiches[0]) {
      stuArr.shift();
      sandwiches.shift();
      clearAllDislike();
      continue;
    } else {
      if(!stuArr[0].dislike) {
        stuArr[0].dislike = true;
        stuArr.push(stuArr.shift());
      } else {
        if(allDislike(stuArr)) {
          break;
        }
      }
    }
  }
  return sandwiches.length;
};
let students = [1,1,0,0], sandwiches = [0,1,0,1];
console.log(countStudents(students, sandwiches));
students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1];
console.log(countStudents(students, sandwiches));
